package com.lkj.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lkj.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lkj.dao.ServerMapper;
import com.lkj.service.ServerServcie;
import com.lkj.utils.PageUtil;

@Service("serverService")
public class ServerServiceImpl implements ServerServcie {

	@Autowired
	private ServerMapper serverDao;
	
	public Server selectByPrimaryKey(int serverid) {
		// TODO Auto-generated method stub
		return serverDao.selectByPrimaryKey(serverid);
	}

	public void insert(Server server) {
		// TODO Auto-generated method stub
		serverDao.insert(server);
	}

	public List getAll() {
		// TODO Auto-generated method stub
		return serverDao.getAll();
	}

	public int getTotalRows(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return serverDao.getTotalRows(map);
	}

	public List<Status> getStatus(PageUtil pageUtil) {
		// TODO Auto-generated method stub
		return serverDao.getStatus(pageUtil);
	}

	public List<Scene> getScenes(PageUtil pageUtil) {
		// TODO Auto-generated method stub
		return serverDao.getScenes(pageUtil);
	}

	public int getTotalRows_scene(PageUtil map) {
		// TODO Auto-generated method stub
		return serverDao.getTotalRows_scene(map);
	}

	public List<Server> getFileServers(PageUtil pageUtil) {
		// TODO Auto-generated method stub
		return serverDao.getFileServers(pageUtil);
	}

	public int getTotalRows_servers(PageUtil map) {
		// TODO Auto-generated method stub
		return serverDao.getTotalRows_servers(map);
	}

	public List<Video> getVideos(PageUtil pageUtil) {
		// TODO Auto-generated method stub
		return serverDao.getVideos(pageUtil);
	}

	public int getTotalRows_video(PageUtil map) {
		// TODO Auto-generated method stub
		return serverDao.getTotalRows_video(map);
	}

	public Integer updateStatus(Status status) {
		// TODO Auto-generated method stub
		if(status.getStatusid()!=null){
			return serverDao.updateStatus(status);
			
		}
		return serverDao.newStatus(status);
	}

	public Integer updateFileServer(Server server) {
		// TODO Auto-generated method stub
		if(server.getServerid()!=null){
			return serverDao.updateFileServer(server);

		}
		return  serverDao.newFileServer(server);
	}

	public Integer updateScene(Scene scene) {
		// TODO Auto-generated method stub
		if(scene.getSceneid()!=null){
			return serverDao.updateScene(scene);

		}
		return  serverDao.updateScene(scene);
	}



	public Server getServerInfo(Integer id) {
		// TODO Auto-generated method stub
		return serverDao.getServerInfo(id);
	}

	public List<Scene> getNervenets() {
		// TODO Auto-generated method stub
		return serverDao.getNervenets();
	}

	public Integer addScene(Scene scene) {
		// TODO Auto-generated method stub
		int sceneid = serverDao.addScene(scene);
		System.out.println(sceneid);
		if(!"".equals(sceneid)&&sceneid!=0){
			scene.setSceneid(sceneid);
			return serverDao.addScene_n(scene);
		}
		return 0;
	}

	public void setStatus(Video video) {
		// TODO Auto-generated method stub
		serverDao.deleteVc(video);
		serverDao.setStatus(video);
	}

	public int getTotalRows_user(PageUtil pageutil) {
		return serverDao.getTotalRows_user(pageutil);
	}

	public List<User> getUsers(PageUtil pageUtil) {
		return serverDao.getUsers(pageUtil);
	}

	public void updateUser(User user) {
		serverDao.updateUser(user);
	}

	public Map<String, Object> login(User user) {
		Map<String,Object> map = new HashMap<String, Object>();
		if (serverDao.check(user)>0){
			User u = serverDao.login(user);
			if(u!=null){
				map.put("msg","success");
				map.put("user",u);
			}else{
				map.put("msg","密码错误");
			}
		}else{
			map.put("msg","没有该用户");
		}

		return map;
	}

}
